package com.ukao.steward.ui.menuLeft.myEarnings;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.BaseFragment;
import com.ukao.steward.bean.IncomeDetailbBean;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.MyDateUtils;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 收支明细
 */
public class IncomeDetailsFragment extends BaseFragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.back_btn)
    ImageView backBtn;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.title_layout)
    RelativeLayout titleLayout;

    Unbinder unbinder;
    @BindView(R.id.income)
    TextView income;
    @BindView(R.id.createTime)
    TextView createTime;
    @BindView(R.id.seq)
    TextView seq;
    @BindView(R.id.balance)
    TextView balance;
    @BindView(R.id.remark)
    TextView remark;
    @BindView(R.id.type)
    TextView type;


    private String mParam1;
    private String mParam2;
    private IncomeDetailbBean.ListBean mIncomeDetail;


    public static IncomeDetailsFragment newInstance(Serializable param1, String param2) {
        IncomeDetailsFragment fragment = new IncomeDetailsFragment();
        Bundle args = new Bundle();
        args.putSerializable(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mIncomeDetail = (IncomeDetailbBean.ListBean) getArguments().getSerializable(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_income_details, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        if (!CheckUtils.isNull(mIncomeDetail)) {
            int expenditure = mIncomeDetail.getExpenditure();
            type.setText(CheckUtils.isEmptyString(mIncomeDetail.getTradeTypeText()));/*收支类型*/
            createTime.setText(MyDateUtils.formatDataTime(mIncomeDetail.getCreateTime()));/*时间*/
            seq.setText(CheckUtils.isEmptyString(mIncomeDetail.getSeq()));/*单号*/
            balance.setText(CheckUtils.isEmptyNumber(mIncomeDetail.getBalance()));/*余额*/
                    remark.setText(CheckUtils.isEmptyString(mIncomeDetail.getRemark()));/*备注*/
            if (!CheckUtils.isNull(expenditure) && expenditure > 0) {/*扣钱*/

                income.setText(CheckUtils.isEmptyNumber(mIncomeDetail.getExpenditure()));
            } else {
                income.setText( CheckUtils.isEmptyNumber(mIncomeDetail.getIncome()));

            }
        }

        title.setText("收支详情");
        titleLayout.setBackgroundColor(getColors(R.color.colorPrimary));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.back_btn,})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                finish();

                break;

        }
    }
}
